
use "D:\百度云同步盘\清华\科研\数据\中国私营企业调查问卷和数据1993-2008\数据\2008_.dta",clear


**merge industry level Party
collapse (mean) party_ind=b24d, by(b17b1) 

sort b17b1

save "D:\百度云同步盘\清华\科研\论文\He & Liu\制度涉入和家族企业应对\数据\party_ind_temp2008.dta",replace

merge 1:m  b17b1 using "D:\百度云同步盘\清华\科研\数据\中国私营企业调查问卷和数据1993-2008\数据\2008_.dta"

replace party_ind=. if b17b1==.



********************************************************************************
********************************* 控制变量 *********************************
********************************************************************************

*****************************
*** Firm Level ***
*****************************

*企业历史
tab b12
g firm_year = 2008-b12

*雇员人数
sum b27b1 // 全部雇员
*sum  // 生产工人
sum b27b1a // 管理人员
sum b27b1b // 技术工人
g employee = b27b1
g employee_managers = b27b1a
g employee_techians = b27b1b
replace employee = . if employee < 0 
replace employee_managers = . if employee_managers < 0 
replace employee_techians = . if employee_techians < 0 
g employee_workers = employee-employee_managers-employee_techians
replace employee_workers = . if employee_workers < 0 
g log_employee = log(employee+1)
g log_employee_workers = log(employee_workers+1)
g log_employee_managers = log(employee_managers+1)
g log_employee_techians = log(employee_techians+1)

***企业资本构成(最近1年)

*所有者权益总额(万元)
sum b14a8b
g interest_total = b14a8b
replace interest_total =. if interest_total <0


*您自己(%)的涉入
g interest_of = b14a1b
replace interest_of =. if interest_of <0
replace interest_of =. if interest_of > 100

*您自己(%)
*g interest_me = b14a1b
*replace interest_me =. if interest_me <0
*replace interest_me =. if interest_me > 100

***企业重大决策权
tab b26a 
	// 1=您本人 2=股东大会 3=董事会 4=您和主要管理人员 
	// 5=您和党组织   6=您和工会 7=其他
g decion_big = b26a
g decion_big_dummy = decion_big
recode decion_big_dummy 1=1 2/7= 0 // 0=非本人 1=本人 
tab decion_big_dummy

***企业日常管理
tab b26b
      // 1=您本人 2=您和其它管理人员 3=您和党组织  4=您和工会 5=其他
	  // 6=其它
g decion_manage = b26b
g decion_manage_dummy = decion_manage
recode decion_manage_dummy 1=1 2/6= 0 // 0=非本人 1=本人
tab decion_manage_dummy

*********************
*Industry Level
*********************

*行业类型 (实体vs非实体-房地产和金融保险)-参考范晓光和吕鹏(2018)
tab b17b1 // 1-19
tab b17b1, nol // 1-19
tab b17b2 
tab b17b3
g indus_1 = b17b1
g indus_2 = b17b2
g indus_3 = b17b3

/*
recode indus_1 10/11=0 1/9=1 12/19=1  // 0=非实体 1=实体
recode indus_2 10/11=0 1/9=1 12/19=1  // 0=非实体 1=实体
recode indus_3 10/11=0 1/9=1 12/19=1  // 0=非实体 1=实体
g indus_real = indus_1
tab indus_real
*/

g industry_man = .
replace industry_man = 0 if indus_1 != 3 & indus_2 != 3 & indus_3 != 3  // 非制造业
replace industry_man = 1 if indus_1 == 3 | indus_2 == 3 | indus_3 == 3  // 制造业
tab industry_man



********************************************************************************
***********************************Individual Level****************************
********************************************************************************

*性别
tab a1
tab a1, nol // 男=1 女=2
g gender = a1
recode gender 1=1 2=0  // 女=0 男=1

*年龄/出生年份
tab a2
g age = 2008-a2

*学历 (0=初中及以下 1=高中 2=大专及以上)-参考范晓光和吕鹏(2018)
tab a3
tab a3, nol 
   //  1=研究生 2=大学 3=大专 4=高中、中专、5=初中 6=小学及以下
g edu_cate = a3
recode edu_cate 5/6=0 4=1 1/3=2 
tab edu_cate

*学历 (0=高中及以下 1=大专及以下)
tab a3
tab a3, nol 
g edu_dummy = a3
recode edu_dummy 1/3=1 4/6=0
tab edu_dummy   

*政治面貌
tab a5 // 1=党员 2=共青团 3=民主党派
g party_mem = a5
replace party_mem = 1 if party_mem == 1
replace party_mem = 0 if party_mem == 2 | party_mem == 3 | party_mem==.
tab party_mem

*两委委员
tab a6a1
tab a6a1, nol // 6=不是 1-5 (乡-全国)
g renda = a6a1
tab a6b1
tab a6b1, nol // 5=不是 1-4 (乡-全国)
g zhengxie = a6b1
g twocm = .
replace twocm = 0 if renda == 6 & zhengxie == 5
replace twocm = 1 if renda==1 | renda==2 | renda==3 | renda==4 | renda==5 | zhengxie==1 | zhengxie==2 | zhengxie==3 | zhengxie==4
tab twocm  // 是=1 否=0
tab renda
tab zhengxie

*工商联
tab c35b // 1=是 2=否
tab c35b, nol
g gongshanglian = c35b
recode gongshanglian 1=1 2=0 // 1=是 0=否
tab gongshanglian

*地位感知(经济/社会/政治) 数值越小，地位越高
tab a11a // 收入水平 1-10
tab a11b // 社会地位
tab a11c // 政治参与
g status_e = a11a
g status_s = a11b
g status_p = a11c
replace status_e =. if status_e <0
replace status_s =. if status_s <0
replace status_p =. if status_p <0

********************************************************************************
********************************* 党建 *********************************
********************************************************************************

*设立党组织(在您的企业中，有无下列组织?) 
sum b24a // 股东会
sum b24b // 董事会
sum b24c // 监事会
sum b24d // 党支部  0=无 1=有
sum b24e // 工会
sum b24f // 职工代表大会
g structure_share = b24a
g structure_chair = b24b
g structure_audit = b24c
g structure_party = b24d
g structure_union = b24e
g structure_assemble = b24f
tab structure_party

*党组织参与决策(您企业的重大决策由谁作出？)
tab b26a 
	// 1=您本人 2=股东大会 3=董事会 4=您和主要管理人员 
	// 5=您和党组织   6=您和工会 7=其他
g decion_party = b26a
recode decion_party 1/4=0 6/7=0 5=1 // 0=非党组织 1=党组织 
tab decion_party

*党组织参与管理(企业日常管理由谁负责?)
tab b26b  // 1=您本人 2=您和其它管理人员 3=您和党组织  4=您和工会 5=职业经理人 6=其它
g manage_party = b26b
recode manage_party 1/2=0 4/6=0 3=1 // 0=非党组织 1=党组织 	 
tab manage_party

*您认为统战部门应如何加强与非公经济人士的联系？ 
tab c40a4 // 加强与私营企业党组织的联系，支持有条件的企业党委设立统战工作部门

*党员人数(到目前为止，在您企业就业的员工中有位中共党员?)
tab c41a
g party_member = c41a
replace party_member =. if party_member < 0

*党员人数占比(党员/员工数)
g party_member_ratio = party_member/employee
replace party_member_ratio =. if party_member_ratio < 0
replace party_member_ratio =. if party_member_ratio > 1

*在您的企业里建立了哪种党组织？
tab c41b // ⑴党委 ⑵总支 ⑶支部 ⑷党小组 ⑸没有建立党组织

*您认为私营企业党组织由哪一种上级党组织管理更有利？ 
tab c41c //(1)属地党委 (2)当地工商联党组 (3)个体私营企业协会党组织 (4)其他（请写明）

*是否担任企业党委书记(如果您是党员，您是否担任了企业党委（总支、支部）书记？)
tab c41d
tab c41d, nol // 1=是 2=否
g firm_shuji = c41d
recode firm_shuji 1=1 2=0 .=0 // 1=是 0=否
tab firm_shuji

*党代表(E.如果您是党代会代表，请问是哪一级的？)
tab c41e
tab c41e, nol 
 // ⑴乡镇（街道）级 ⑵县（市）级 ⑶地市和副省级 ⑷省级 ⑸全国级 ⑹不是党代会代表
g cpc_deputy = c41e

*党委委员 (F.如果您是地方和基层党委委员，请问是哪一级的？)
tab c41f
tab c41f, nol  
 // ⑴乡镇（街道）级 ⑵县（市）级 ⑶地市和副省级 ⑷省级 (5)不担任党委委员
g cpc_cm = c41f

********************************************************************************
********************************* 经营 *********************************
********************************************************************************

*企业资产 - 所有者权益总额(万元)
sum b14a8b
*g interest_total = b14a8b
*replace interest_total =. if interest_total <0

******
*绩效*
******

*销售收入
g revenue_latest = b20a
replace revenue_latest =. if revenue_latest < 0
g log_revenue_latest = log(revenue_latest+1)

winsor2 revenue_latest, cuts(1 99) suffix(_w) label // 缩尾
sum revenue_latest_w 
g log_revenue_latest_w = log(revenue_latest_w+1)

*利润
sum b20d
g profit_latest = b20d
replace profit_latest =. if profit_latest < 0
g log_profit_latest = log(profit_latest+1)

winsor2 profit_latest, cuts(1 99) suffix(_w) label // 缩尾
sum profit_latest_w profit_latest
g log_profit_latest_w = log(profit_latest+1)


******
*投资
******

*新增投资(费用/强度/是否) 万元
g invest = b21a  // 费用
replace invest =. if invest < 0 
g log_invest = log(invest+1)

winsor2 invest, cuts(1 99) suffix(_w) label // 缩尾
sum invest_w 
g log_invest_w = log(invest+1)

*是否投资
g invest_dummy = invest  // 是否
replace invest_dummy = 0 if invest_dummy == 0 
replace invest_dummy = 1 if invest_dummy > 0 
tab invest_dummy

*新增投资/销售收入(强度)
g invest_ratio = invest / revenue_latest
replace invest_ratio =. if invest_ratio < 0
replace invest_ratio =. if invest_ratio > 100 
g log_invest_ratio = log(invest_ratio+1)

g invest_ratio_w = invest_w / revenue_latest_w // 缩尾
replace invest_ratio_w =. if invest_ratio_w < 0
replace invest_ratio_w =. if invest_ratio_w > 100 
replace invest_ratio_w =. if invest_ratio_w > 1

************
*创新
************

*创新投入:研发投入(万元) (2001 年您的企业新产品、新技术、新项目的研发投资)
g inno_in = b19a // 费用
replace inno_in =. if inno_in < 0
g log_inno_in = log(inno_in+1)

*创新投入:是否研发投入
g inno_in_dummy = inno_in // 是否
replace inno_in_dummy = 0 if inno_in_dummy == 0
replace inno_in_dummy = 1 if inno_in_dummy > 0
tab inno_in_dummy

*创新投入:研发投入/销售收入
g inno_in_ratio = inno_in / revenue_latest  // 强度
replace inno_in_ratio =. if inno_in_ratio < 0
replace inno_in_ratio =. if inno_in_ratio > 100

*创新产出(专利/自主设计产品)
g inno_out_patent = b19b1 // 专利
g inno_out_design = b19b2 // 自主设计产品 
replace inno_out_patent =. if inno_out_patent < 0
replace inno_out_design =. if inno_out_design < 0


********************************************************************************
********************************* 资源获取 *********************************
********************************************************************************
************
*贷款
************

*国有银行 (万元)
g loan_bank_state = b22a1a
replace loan_bank_state =. if loan_bank_state < 0
g log_loan_bank_state = log(loan_bank_state+1)

*股份制银行(万元)
g loan_bank_stock = b22a1b
replace loan_bank_stock =. if loan_bank_stock < 0
g log_loan_bank_stock = log(loan_bank_stock+1)

*城市商业银行(万元)
g loan_bank_city = b22a1c
replace loan_bank_city =. if loan_bank_city < 0
g log_loan_bank_city = log(loan_bank_city+1)

*银行贷款总计 (万元)
g loan_bank = loan_bank_state+loan_bank_stock+loan_bank_city
replace loan_bank =. if loan_bank < 0
g log_loan_bank = log(loan_bank+1)

winsor2 loan_bank, cuts(1 99) suffix(_w) label // 缩尾
sum loan_bank_w loan_bank
g log_loan_bank_w = log(loan_bank+1)


*民间贷款 (万元)
g loan_private = b22a1d
replace loan_private =. if loan_private < 0
g log_loan_private = log(loan_private+1)


********************************************************************************
********************************* 行政干预 *********************************
********************************************************************************

*摊派 (万元)
g tanpai = b21c  // 费用
replace tanpai =. if tanpai < 0 
g log_tanpai = log(tanpai+1)

*是否摊派
g tanpai_dummy = tanpai  // 是否
replace tanpai_dummy = 0 if tanpai_dummy == 0 
replace tanpai_dummy = 1 if tanpai_dummy > 0 

*摊派/销售收入
g tanpai_ratio = tanpai / revenue_latest 
replace tanpai_ratio =. if tanpai_ratio < 0
replace tanpai_ratio =. if tanpai_ratio > 100
g log_tanpai_ratio = log(tanpai_ratio+1)

*应酬(万元)
g yingchou = b21e  // 费用
replace yingchou =. if yingchou < 0 
g log_yingchou = log(yingchou+1)

*是否应酬
g yingchou_dummy = yingchou  // 是否
replace yingchou_dummy = 0 if yingchou_dummy == 0 
replace yingchou_dummy = 1 if yingchou_dummy > 0 
tab yingchou_dummy

*应酬/销售收入
g yingchou_ratio = yingchou / revenue_latest  // 强度
replace yingchou_ratio =. if yingchou_ratio < 0
replace yingchou_ratio =. if yingchou_ratio > 100
g log_yingchou_ratio = log(yingchou_ratio+1)


********************************************************************************
********************************* 外部社会责任 *********************************
********************************************************************************

*******
*捐赠*
******
*drop   juan_dummy juan_ratio

*捐赠费用 万元
g juan = b21d  // 费用
replace juan =. if juan < 0 
g log_juan = log(juan+1)

winsor2 juan, cuts(1 99) suffix(_w) label // 缩尾
sum juan_w juan
g log_juan_w = log(juan_w+1)


*是否捐赠
g juan_dummy = juan  // 是否
replace juan_dummy = 0 if juan_dummy == 0 
replace juan_dummy = 1 if juan_dummy > 0 
tab juan_dummy

*捐赠费用/销售收入
g juan_ratio = juan/revenue_latest  // 强度
sum juan_ratio
replace juan_ratio =. if juan_ratio > 1

g juan_ratio_w = juan_w/revenue_latest_w  // 缩尾
sum juan_ratio_w
replace juan_ratio_w =. if juan_ratio_w > 1

**********
*治理污染*
**********
*drop zhiwu log_zhiwu zhiwu_dummy zhiwu_ratio

*治污费用 元
g zhiwu = b30c/10000  // 万元
replace zhiwu =. if zhiwu < 0 
g log_zhiwu = log(zhiwu+1)

winsor2 zhiwu, cuts(1 99) suffix(_w) label // 缩尾
sum zhiwu_w zhiwu
g log_zhiwu_w = log(zhiwu_w+1)

*是否治污
g zhiwu_dummy = zhiwu  // 是否
replace zhiwu_dummy = 0 if zhiwu_dummy == 0 
replace zhiwu_dummy = 1 if zhiwu_dummy > 0 
tab zhiwu_dummy

*治污费用/销售收入
g zhiwu_ratio = zhiwu/revenue_latest  // 强度
sum zhiwu_ratio
replace zhiwu_ratio =. if zhiwu_ratio > 1

g zhiwu_ratio_w = zhiwu_w /revenue_latest_w  // 强度
sum zhiwu_ratio_w
replace zhiwu_ratio_w =. if zhiwu_ratio_w > 1

********************************************************************************
********************************* 内部社会责任 *********************************
********************************************************************************

********
*工资*
********

*总工资 万元
sum b28a
g wage = b28a
replace wage =. if wage < 0
g log_wage = log(wage+1)

*人均工资(手动计算)
g per_wage = wage / employee
tab per_wage
sum per_wage, de
g log_per_wage = log(per_wage+1)

winsor2 per_wage, cuts(1 99) suffix(_w) label // 缩尾
sum per_wage_w per_wage
g log_per_wage_w = log(per_wage_w+1)

********
*劳保*
********

*劳保费用
sum b28c1
g labor_protect = b28c1
replace labor_protect =. if labor_protect < 0
g log_labor_protect = log(labor_protect+1)

*是否有劳保费用
g labor_protect_dummy = labor_protect // 是否
replace labor_protect_dummy = 0 if labor_protect_dummy == 0
replace labor_protect_dummy = 1 if labor_protect_dummy > 0

*人均劳保费用
g per_labor_protect = labor_protect / employee
tab per_labor_protect
sum per_labor_protect, de
g log_per_labor_protect = log(per_labor_protect+1)

************
*社会保险*
************
sum b28d1a b28e1 b28f1 b28g1 b28h1 //  参保人数 (医疗/养老/工伤/失业/生育)
sum b28d1b b28e2 b28f2 b28g2 b28h2 // 参保费用 (医疗/养老/工伤/失业/生育)

*单项参保人数
g ins_med_num = b28d1a
g ins_old_num = b28e1
g ins_injury_num = b28f1
g ins_unemploy_num = b28g1
g ins_birth_num = b28h1

*单项社保支出
g ins_med_fee = b28d1b
g ins_old_fee = b28e2
g ins_injury_fee = b28f2
g ins_unemploy_fee = b28g2
g ins_birth_fee = b28h2
g log_ins_med_fee = log(ins_med_fee+1)
g log_ins_old_fee = log(ins_old_fee+1)
g log_ins_ins_injury_fee = log(ins_injury_fee+1)
g log_ins_unemploy_fee = log(ins_unemploy_fee+1)
g log_ins_ins_birth_fee = log(ins_birth_fee+1)

*人均社保费用(单项)
g per_ins_med_fee = ins_med_fee/employee
g per_ins_old_fee = ins_old_fee/employee
g per_ins_injury_fee = ins_injury_fee/employee
g per_ins_unemploy_fee = ins_unemploy_fee/employee
g per_ins_birth_fee = ins_birth_fee/employee
replace per_ins_med_fee =. if per_ins_med_fee <0
replace per_ins_old_fee =. if per_ins_old_fee <0
replace per_ins_injury_fee =. if per_ins_injury_fee <0
replace per_ins_unemploy_fee =. if per_ins_unemploy_fee <0
replace per_ins_birth_fee =. if per_ins_birth_fee <0
g log_per_ins_med_fee = log(per_ins_med_fee+1)
g log_per_ins_old_fee = log(per_ins_old_fee+1)
g log_per_ins_injury_fee = log(per_ins_injury_fee+1)
g log_per_ins_unemploy_fee = log(per_ins_unemploy_fee+1)
g log_per_ins_birth_fee = log(per_ins_birth_fee+1)

*参保率(单项)
g ins_med_num_ratio = ins_med_num / employee
g ins_old_num_ratio = ins_old_num / employee
g ins_injury_num_ratio = ins_injury_num / employee
g ins_unemploy_num_ratio = ins_unemploy_num / employee
g ins_birth_num_ratio = ins_birth_num / employee

*总社保支出 万元
g ins_fare = b28d1b+b28e2+b28f2+b28g2+b28h2  // 参保费用(医疗/养老/失业)
replace ins_fare =. if ins_fare <0
g log_ins_fare = log(ins_fare+1)

*总参保人数
recode b28d1a b28e1 b28f1 b28g1 b28h1 (.=0)
g ins_num = b28d1a+b28e1+b28f1+b28g1+b28h1  // 参保人数(医疗/养老/失业)
replace ins_num =. if ins_num <0
*replace ins_num =. if b28d1a==0&b28e1==0&b28f1==0&b28g1==0&b28h1==0
sum ins_num



*是否有社保支出
g ins_fare_dummy = ins_fare // 是否
replace ins_fare_dummy = 0 if ins_fare_dummy == 0
replace ins_fare_dummy = 1 if ins_fare_dummy > 0

*总人均社保支出
g per_ins_fare = ins_fare/employee  
replace per_ins_fare =. if per_ins_fare <0
g log_per_ins_fare = log(per_ins_fare+1)

winsor2 per_ins_fare, cuts(1 99) suffix(_w) label // 缩尾
sum per_ins_fare_w per_ins_fare
g log_per_ins_fare_w = log(per_ins_fare_w+1)

*总参保率(参保人数/职工数)
g ins_num_ratio = ins_num / employee
replace ins_num_ratio =. if ins_num_ratio <0
replace ins_num_ratio =. if ins_num_ratio >1

********
*员工培训*
*********

*培训费用(万元)
g train_fare = b19e  // 费用
replace train_fare =. if train_fare <0
g log_train_fare = log(train_fare+1)

*是否培训
g train_fare_dummy = train_fare // 是否
replace train_fare_dummy = 0 if train_fare_dummy == 0
replace train_fare_dummy = 1 if train_fare_dummy > 0

*人均培训(总职工数)
g per_train_fare = train_fare/employee // 人均费用
replace per_train_fare =. if per_train_fare <0
g log_per_train_fare = log(per_train_fare+1)

*培训/销售收入
g train_ratio = train_fare / revenue_latest  // 强度
replace train_ratio =. if train_ratio > 1

********
*个人合同*
*********

*个人合同签订人数
g contract_i_num = b27c1 // 人数
replace contract_i_num =. if contract_i_num <0

*个人合同签订率 = 签订人数/员工数
g contract_i_ratio = contract_i_num/employee  // 
replace contract_i_ratio =. if contract_i_ratio <0
replace contract_i_ratio =. if contract_i_ratio > 1
sum contract_i_ratio

********
*集体合同*
*********

*集体合同签订人数
g contract_c_num = b27c2 // 人数
replace contract_c_num =. if contract_c_num <0

*集体合同签订率 = 签订人数/员工数
g contract_c_ratio = contract_c_num/employee  // 签订率
replace contract_c_ratio =. if contract_c_ratio <0
replace contract_c_ratio =. if contract_c_ratio > 1

********************************************************************************
********************************* 家族涉入 *********************************
********************************************************************************

***所有者权益占比
*您自己(%)
g interest_me = b14a1b
replace interest_me =. if interest_me <0
replace interest_me =. if interest_me > 100
sum interest_m

*亲属在股东会的人数
g share_fam_num = b26c1
replace share_fam_num =. if share_fam_num <0

*亲属在董事会的人数
g chair_fam_num = b26c2 
replace chair_fam_num =. if chair_fam_num <0

*亲属担任高管的人数
g manager_fam_num = b26c3
replace manager_fam_num =. if manager_fam_num <0

********************************************************************************
*************************** Regional Level **************************
********************************************************************************

****生成省份
g shengfen = n1r

// 省份重新编码
g prov =.
replace	prov	=	110000	if	shengfen	==	1
replace	prov	=	120000	if	shengfen	==	2
replace	prov	=	130000	if	shengfen	==	3
replace	prov	=	140000	if	shengfen	==	4
replace	prov	=	150000	if	shengfen	==	5
replace	prov	=	210000	if	shengfen	==	6
replace	prov	=	220000	if	shengfen	==	7
replace	prov	=	230000	if	shengfen	==	8
replace	prov	=	310000	if	shengfen	==	9
replace	prov	=	320000	if	shengfen	==	10
replace	prov	=	330000	if	shengfen	==	11
replace	prov	=	340000	if	shengfen	==	12
replace	prov	=	350000	if	shengfen	==	13
replace	prov	=	360000	if	shengfen	==	14
replace	prov	=	370000	if	shengfen	==	15
replace	prov	=	410000	if	shengfen	==	16
replace	prov	=	420000	if	shengfen	==	17
replace	prov	=	430000	if	shengfen	==	18
replace	prov	=	440000	if	shengfen	==	19
replace	prov	=	450000	if	shengfen	==	20
replace	prov	=	460000	if	shengfen	==	21
replace	prov	=	500000	if	shengfen	==	22
replace	prov	=	510000	if	shengfen	==	23
replace	prov	=	520000	if	shengfen	==	24
replace	prov	=	530000	if	shengfen	==	25
replace	prov	=	540000	if	shengfen	==	26
replace	prov	=	610000	if	shengfen	==	27
replace	prov	=	620000	if	shengfen	==	28
replace	prov	=	630000	if	shengfen	==	29
replace	prov	=	640000	if	shengfen	==	30
replace	prov	=	650000	if	shengfen	==	31
tab prov

// 地区变量  2=东部 1=中部 0=西部
g diqu =.
replace	diqu	=	2	if	prov	==	110000
replace	diqu	=	2	if	prov	==	120000
replace	diqu	=	2	if	prov	==	130000
replace	diqu	=	1	if	prov	==	140000
replace	diqu	=	1	if	prov	==	150000
replace	diqu	=	2	if	prov	==	210000
replace	diqu	=	1	if	prov	==	220000
replace	diqu	=	1	if	prov	==	230000
replace	diqu	=	2	if	prov	==	310000
replace	diqu	=	2	if	prov	==	320000
replace	diqu	=	2	if	prov	==	330000
replace	diqu	=	1	if	prov	==	340000
replace	diqu	=	2	if	prov	==	350000
replace	diqu	=	1	if	prov	==	360000
replace	diqu	=	2	if	prov	==	370000
replace	diqu	=	1	if	prov	==	410000
replace	diqu	=	1	if	prov	==	420000
replace	diqu	=	1	if	prov	==	430000
replace	diqu	=	2	if	prov	==	440000
replace	diqu	=	2	if	prov	==	450000
replace	diqu	=	2	if	prov	==	460000
replace	diqu	=	0	if	prov	==	500000
replace	diqu	=	0	if	prov	==	510000
replace	diqu	=	0	if	prov	==	520000
replace	diqu	=	0	if	prov	==	530000
replace	diqu	=	0	if	prov	==	540000
replace	diqu	=	0	if	prov	==	610000
replace	diqu	=	0	if	prov	==	620000
replace	diqu	=	0	if	prov	==	630000
replace	diqu	=	0	if	prov	==	640000
replace	diqu	=	0	if	prov	==	650000
tab diqu

*************************************
***建模分析
***************************************

*2008 年的家族涉入

gen interest_me_dy =0 if interest_me < 50
replace interest_me_dy =1 if interest_me > 49.9999999 & interest_me < 101
tab interest_me_dy


**********************
***数据清理***
**********************
/*
drop if structure_party == .
*drop if ins_num_ratio==.
drop if interest_of==.
drop if log_employee == .
drop if party_ind ==.
drop if party_mem == .
drop if firm_year==.
drop if log_profit_latest== .
drop if industry_man==.
drop if firm_year==.
drop if gender == .
drop if edu_dummy == .
drop if twocm == .
drop if prov == .
*/


lab var structure_party "Build a Party Branch"
lab var ins_num_ratio "Percent of Employees with Social Securities"
lab var interest_of "Family Involvement"
lab var log_employee "Firm size (logged)"
lab var employee "Firm size"
lab var party_ind "Percent of Party building in an industry"
lab var firm_year "Firm age"
lab var profit_latest "Firm profit"
lab var industry_man "Manufacturing"
lab var gender "Male"
lab var edu_dummy "College education and above"
lab var twocm "Congress delegates or CCPCC members"
lab var party_mem "Party members"


**summary statistics

asdoc sum  structure_party ins_num_ratio interest_of employee  party_ind party_mem firm_year ///
profit_latest_w industry_man gender edu_dummy twocm,replace(table 2) dec(2) label




**********************
***select variables***
**********************
/*
***Chapter 6 璁剧珛鍏氱粍缁%X87
g year = 2008
keep year structure_party interest_me interest_me_dy decion_big_dummy decion_manage_dummy ///
	      firm_year employee log_employee revenue_latest log_revenue_latest ///
			profit_latest log_profit_latest indus_real ///
			age gender edu_dummy party_mem twocm gongshanglian status_s status_p status_e ///
			diqu prov party_member ///
			revenue_latest_w log_revenue_latest_w profit_latest_w log_profit_latest_w // 缂╁熬

***Chapter 7 绀句細鍔熻兘
*g year = 2008
keep year structure_party interest_me interest_me_dy decion_big_dummy ///
	      firm_year employee log_employee revenue_latest log_revenue_latest ///
			profit_latest log_profit_latest indus_real ///
			age gender edu_dummy party_mem twocm gongshanglian status_s status_p status_e ///
			diqu prov party_member ///
			juan log_juan juan_dummy juan_ratio zhiwu log_zhiwu zhiwu_dummy zhiwu_ratio ///
			wage per_wage ///
			labor_protect log_labor_protect labor_protect_dummy per_labor_protect ///
			ins_fare log_ins_fare ins_num ins_fare_dummy per_ins_fare	ins_num_ratio ///
			train_fare log_train_fare train_fare_dummy	per_train_fare	train_ratio ///
			contract_i_num	contract_i_ratio contract_c_num	contract_c_ratio ///
 			revenue_latest_w log_revenue_latest_w profit_latest_w log_profit_latest_w /// 缂╁熬
			juan_w log_juan_w juan_ratio_w zhiwu_w log_zhiwu_w zhiwu_ratio_w /// 缂╁熬
			per_wage_w log_per_wage_w per_ins_fare_w log_per_ins_fare_w  // 缂╁熬
*/

********************************=********************************=**************
*************************************** 回归分析 ******************************
********************************=********************************=**************

***Table 1
set more off

misstable sum ins_num_ratio  structure_party interest_of party_mem log_employee party_ind firm_year ///
log_profit_latest industry_man gender edu_dummy twocm prov


misstable sum   structure_party twocm prov


logit structure_party c.interest_of i.party_mem  c.firm_year c.log_profit_latest_w ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov 

eststo m1
	
		
logit structure_party c.interest_of c.log_employee i.party_mem c.firm_year ///
c.log_profit_latest_w i.industry_man i.gender i.edu_dummy i.twocm i.prov 

eststo m2

/*
logit firm_shuji c.interest_of party_ind i.party_mem c.firm_year  c.log_profit_latest ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m3

logit firm_shuji c.interest_of c.log_employee  party_ind i.party_mem c.firm_year ///
c.log_profit_latest i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m4
*/

esttab m1 m2 using decouple_2008.rtf, b(3) se(3) pr2 star(* 0.05 ** 0.01 *** 0.001) ///
nobase replace drop(*.prov*)


***********************
***social security
***********************
regress ins_num_ratio c.interest_of i.party_mem  c.firm_year c.log_profit_latest_w ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m5 


regress ins_num_ratio c.interest_of i.party_mem structure_party c.firm_year c.log_profit_latest_w ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov
eststo m6


esttab m5 m6 using socrate_2008.rtf, b(3) se(3) r2 star(* 0.05 ** 0.01 *** 0.001) ///
nobase replace drop(*.prov*)

exit





set more off
logit structure_party c.interest_me c.firm_year c.log_employee c.log_profit_latest i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
    eststo
logit structure_party c.decion_big_dummy c.firm_year c.log_employee c.log_profit_latest i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
    eststo 			
esttab using chapter6_t2_2008.rtf, b(3) se(3) pr2 star(* 0.10 ** 0.05 *** 0.01) nolabel replace
eststo clear


***Table 1:家族涉入与设立党组织***
probit structure_party c.interest_me c.firm_year c.log_employee c.log_profit_latest c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
//"结果:家族涉入程度越高，建立党组织的可能性越低"
probit structure_party c.decion_big_dummy  c.firm_year c.log_employee c.log_profit_latest c.interest_me  i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
//"结果:不显著"

***Table 1:制度环境与设立党组织***

/*营商环境感知*/

/*地位感知*/
probit structure_party c.status_e c.firm_year c.log_employee c.log_profit_latest c.interest_me c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
probit structure_party c.status_s c.firm_year c.log_employee c.log_profit_latest c.interest_me c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
probit structure_party c.status_p c.firm_year c.log_employee c.log_profit_latest c.interest_me c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov


regress ins_num_ratio structure_party c.interest_me c.decion_big_dummy  c.firm_year c.log_employee c.log_profit_latest c.interest_me  ///
i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

exit


/*
winsor employee,gen(Wrenshu) p(0.05)

recode Wrenshu (1/50=1 "1-50")(51/100=2 "51-100")(101/200=3 "101-200") ///
(201/300=4 "201-300")(301/max=5 "301+"),gen(renshu_d) lab(renshu_dlab)

***party building

logit structure_party  interest_m 

exit

regress log_profit_latest_w structure_party


logit structure_party i.renshu_d interest_m party_mem share_fam_num chair_fam_num manager_fam_num  

regress log_profit_latest_w structure_party i.renshu_d interest_m party_mem share_fam_num chair_fam_num manager_fam_num party_member 

logit firm_shuji  interest_m party_mem share_fam_num chair_fam_num manager_fam_num party_member if structure_party==1

regress log_per_labor_protect structure_party interest_m party_mem share_fam_num chair_fam_num manager_fam_num party_member
*/
